import { defineConfig, loadEnv } from "vite";


import viteDevConfig from "./vite.dev.config";
import viteProdConfig from "./vite.prod.config";
import viteBaseConfig from "./vite.base.config";

const envResolver = {
    "build":() => {
        console.log('-------生产环境------')
        return {...viteProdConfig,...viteBaseConfig}
    },
    "serve":(env) =>{
        console.log('-------开发环境------');
        // console.log(env.ENV_DEV_URL);
        return {...viteDevConfig,...viteBaseConfig}
        
    }
}

export default defineConfig(({ command = "build" | "serve", mode }) => {

    // 根据当前模式和当前工作目录加载环境变量
    const env = loadEnv(mode, process.cwd(), "");
    // Resolve and execute the appropriate command from the `envResolver` object.
    return envResolver[command](env);
});

